import os
import shutil

# 设置下载目录路径
download_folder = os.path.join(os.path.expanduser('~'), 'Downloads')

# 设置怪物文件夹路径
monster_folder = os.path.join(download_folder, '怪物')

# 设置目标文件夹路径
target_folder = os.path.join(download_folder, 'stand')

# 如果目标文件夹不存在，则创建
if not os.path.exists(target_folder):
    os.makedirs(target_folder)

# 遍历每个怪物文件夹
for monster_name in os.listdir(monster_folder):
    monster_path = os.path.join(monster_folder, monster_name)
    if os.path.isdir(monster_path):
        # 遍历每个怪物文件夹下的文件夹
        for folder_name in os.listdir(monster_path):
            folder_path = os.path.join(monster_path, folder_name)
            if os.path.isdir(folder_path):
                # 判断文件夹是否为_stand_3
                if 'stand_3' in folder_name:
                    # 复制图片
                    image_path = os.path.join(folder_path, '3_stand_0.png')
                    if os.path.exists(image_path):
                         # 获取图片文件名
                        image_name = os.path.basename(image_path)
                        # 获取图片文件扩展名
                        image_ext = os.path.splitext(image_name)[1]
                        # 只处理 png 文件
                        if image_ext.lower() != '.png':
                            continue
                        # 生成新文件名
                        new_image_name = f"{monster_name}_{image_ext}"
                        # 复制图片
                        shutil.copy(image_path, target_folder)
                        # 重命名图片
                        os.rename(os.path.join(target_folder, image_name), os.path.join(target_folder, new_image_name))
                        print(f'复制图片 {image_path} 到 {target_folder} 成功，重命名为 {new_image_name}')